<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - byte_orderer_kernel_abstract.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#undef</font> DLIB_BYTE_ORDEREr_ABSTRACT_ 
<font color='#0000FF'>#ifdef</font> DLIB_BYTE_ORDEREr_ABSTRACT_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

    <font color='#0000FF'>class</font> <b><a name='byte_orderer'></a>byte_orderer</b> 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                This object has no state.

            WHAT THIS OBJECT REPRESENTS
                This object simply provides a mechanism to convert data from a
                host machine's own byte ordering to big or little endian and to 
                also do the reverse.

                It also provides a pair of functions to convert to/from network byte
                order where network byte order is big endian byte order.  This pair of
                functions does the exact same thing as the host_to_big() and big_to_host()
                functions and is provided simply so that client code can use the most 
                self documenting name appropriate.

                Also note that this object is capable of correctly flipping the contents 
                of arrays when the arrays are declared on the stack.  e.g.  You can  
                say things like:
                int array[10]; 
                bo.host_to_network(array);
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='byte_orderer'></a>byte_orderer</b> <font face='Lucida Console'>(</font>        
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures                
                - #*this is properly initialized
            throws
                - std::bad_alloc
        !*/</font>

        <font color='#0000FF'>virtual</font> ~<b><a name='byte_orderer'></a>byte_orderer</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - any resources associated with *this have been released
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='host_is_big_endian'></a>host_is_big_endian</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (the host computer is a big endian machine) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='host_is_little_endian'></a>host_is_little_endian</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (the host computer is a little endian machine) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='host_to_network'></a>host_to_network</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from host byte order 
                  to network byte order.
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='network_to_host'></a>network_to_host</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from network byte order
                  to host byte order.
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='host_to_big'></a>host_to_big</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from host byte order 
                  to big endian byte order.
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='big_to_host'></a>big_to_host</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from big endian byte order
                  to host byte order.
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='host_to_little'></a>host_to_little</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from host byte order 
                  to little endian byte order.
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='little_to_host'></a>little_to_host</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> item
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - #item == the value of item converted from little endian byte order
                  to host byte order.
        !*/</font>

    <b>}</b>;    
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_BYTE_ORDEREr_ABSTRACT_ 
</font>

</pre></body></html>